package com.spring.demo5.eg1;

/**
 * 模拟资金操作
 *
 * @author vhans
 */
public class FundService {
    // 账户余额
    public double balance = 1000;

    // 模拟充值
    public double recharge(String username, double price) {
        System.out.printf("%s充值%s%n", username, price);
        this.balance += price;
        return this.balance;
    }

    // 模拟提现
    public double cashOut(String username, double price) {
        if (this.balance < price) {
            throw new RuntimeException("余额不足!");
        }
        System.out.printf("%s提现%s%n", username, price);
        this.balance -= price;
        return this.balance;
    }

    // 获取余额
    public double getBalance(String username) {
        return balance;
    }
}
